-
Notifications
You must be signed in to change notification settings - Fork 38
fix: reduce CPU usage when stdin is null #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
3afaf6b to
7e4ae18
Compare
There are some use-cases in which stdin will not be attached to the shpool client. Right now when that happens, one thread is busy-waiting on stdin. This fix adds a 200ms delay to the polling. refs: shell-pool#243
7e4ae18 to
84f2433
Compare
ethanpailes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this is the best fix for this problem. shpool attach processes should always corrispond to an actually attached terminal, so the right thing to do is probably to just detach from the session when we read an EOF off of stdin.
This is probably worth merging for now, but I think we should leave #243 open until we can write the more principled detach fix.
| loop { | ||
| let nread = stdin.read(&mut buf).context("reading stdin from user")?; | ||
| if nread == 0 { | ||
| thread::sleep(STDIN_POLL_DUR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind adding a comment here explaining that this is just a tmp mitigation until we can gracefully detach in the face of EOF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think hanging up here may be as simple as just returning Ok(()). It looks like that breaks a few tests, though hopefully just for timing reasons, so it's not entirely trivial. We probably want to write a new test ensuring that shpool attach with a null stdin does create the session as you would expect and the early hangup doesn't cause trouble as well.
There are some use-cases in which stdin will not be attached to the shpool client. Right now when that happens, one thread is busy-waiting on stdin. This fix adds a 200ms delay to the polling.
Fixes #243